@echo off
REM Map File Parser Batch Script for Windows
REM Usage: parse_map.bat <map_file> [output_file] [sort_option]

if "%1"=="" (
    echo Usage: parse_map.bat ^<map_file^> [output_file] [sort_option]
    echo.
    echo Examples:
    echo   parse_map.bat M6_HMI_LOADER.map
    echo   parse_map.bat M6_HMI_LOADER.map report.txt
    echo   parse_map.bat M6_HMI_LOADER.map ram_analysis.txt ram
    echo.
    echo Sort options: total, rom, ram (default: total)
    pause
    exit /b 1
)

set MAP_FILE=%1
set OUTPUT_FILE=%2
set SORT_OPTION=%3

if "%OUTPUT_FILE%"=="" set OUTPUT_FILE=%~n1_memory_report.txt
if "%SORT_OPTION%"=="" set SORT_OPTION=total

echo Parsing map file: %MAP_FILE%
echo Output file: %OUTPUT_FILE%
echo Sort by: %SORT_OPTION%
echo.

python map_parser.py "%MAP_FILE%" -o "%OUTPUT_FILE%" -s %SORT_OPTION%

if %ERRORLEVEL% EQU 0 (
    echo.
    echo Report generated successfully: %OUTPUT_FILE%
) else (
    echo.
    echo Error occurred during parsing.
)

pause
